<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
  import DialogEditor from '@/components/DialogEditor'
  import dialogMixins from '@/utils/commonDialogMixins'
  import {mRequest} from '@/utils/request'
  export default {
    mixins: [dialogMixins],
    components: {DialogEditor},
    data () {
      return {
        dataFormConfig:{
          id: {
            hidden: true
          },
          orderTime: {
            label: '订单时间',
            type: 'date',
            placeholder: '请选择订单时间'
          },
          contractOrderId:{
            label: '合同编号',
            placeholder: '请选择合同编号',
            type: 'list',
            filterable: true,
            list: [],
            selectCallback: this.contractOrderSelectCallback,
          },
          deepOrderNo: {
            label: '订单编号',
            disabled: true
          },
          orderSource:{
            type: 'radio',
            label: '订单来源',
            radioBorder: true,
            radioList: [
              {text: '来料加工', label: 1},
            ],
            default:1
          },
          productId: {
            label: '产品编号',
            type: 'list',
          //  selectCallback: this.deepProductSelectCallback,
            filterable: true,
            list: [],
            placeholder: '请选择产品',
           // isNeedAdd: true,
          //  addNewItemFunc: this.addNewDeepProduct
          },

          clientId: {
            type: 'list',
            list: [],
            label: '客户名',
            filterable: true,
            placeholder: '请输入客户名',
            isNeedAdd: true,
            addNewItemFunc: this.addNewClientInfo
          },
          deliveryTime: {
            label: '交货时间',
            type: 'date',
            placeholder: '请选择交货时间'
          },

          orderProductNumber: {
            label: '订单数量',
            type: 'number',
            max: 10000000,
            default: 0
          },
            deepCategoryList: {
            reply: () => !this.dataForm.id,
            label: '深加工方式',
            type: 'listAndInput',
            listPlaceholder: '请选择加工方式',
            inputPlaceholder: '请输入色号',
            listName: 'deepCategoryId',
            inputName: 'colorNo',
            numberName: 'unitPrice',
            otherAttrs: ['id'],
            list: []
          },
          deepCategoryId:{
            reply: () => this.dataForm.id,
            label: '深加工方式',
            type: 'list',
            placeholder: '请选择深加',
            list: []
          },

          colorNo: {
            reply: () => this.dataForm.id,
            label: '色号'
          },
          deepProductImage:{
            label: '深加工样图',
            type: 'uploadImage',
            imageType: 'uploadProductImage'
          },
          invoiceTax: {
            label: '是否开票',
            type: 'radio',
            radioBorder: true,
            radioList: [
              {text: '不开票', label: 0},
              {text: '开票', label: 1}
            ],
            default:0
          },
          productPrice: {
            label: '单价',
            type: 'number',
            max: 10000,
            default: 0,
            reply: () => this.dataForm.id,
          },
          advancePayment: {
            label: '预付款金额',
            type: 'number',
            max: 10000000,
            default: 0
          },
          boxSupplyWay: {
            label: '包装方式',
            type: 'radio',
            radioList: [
              {text: '自制纸箱', label: 0},
              {text: '托盘', label: 1},
              {text: '客供纸箱', label: 2},
              {text: '套袋', label: 3},
              {text: '不套袋', label: 4}
            ],
            default: 0
          },
          remark: {
            label: '备注',
            inputType: 'textarea',
            placeholder: '请输入备注'
          },
          status: {
            label: '订单状态',
            type: 'radio',
            radioBorder: false,
            radioList: [
              {text: '光瓶待生产', label: 0},
              {text: '暂时下线', label: 1},
              {text: '加急', label: 2},
              {text: '正常', label: 3},
              {text: '生产中', label: 4},
              {text: '生产完成', label: 5},
              {text: '出库中', label: 10},
              {text: '出库完成', label:11},
              {text: '取消', label: 99}
            ],
            default: 2
          }
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.initDeepCategoryList('deepCategoryList')
        this.initDeepCategoryList('deepCategoryId')
        this.initProductInfoList('productId')
        this.initContractOrderInfoList('contractOrderId')
        this.initClientInfoList()
        this.$refs.dialog.initDialog({
          dataForm: this.dataForm,
          config: this.dataFormConfig,
          stepsConfig: this.stepsConfig,
          dataRule: this.getNeedDataRule('productId','orderTime','clientId', 'deliveryTime', 'productId', 'orderProductNumber', 'status'),
          initApi: 'deepApi/deepOrderDetailInfo',
          saveApi: 'deepApi/saveDeepOrderDetail',
          updateApi: 'deepApi/updateDeepOrderDetail',
          objectName: 'deepOrderDetail'
        })

      },
      // deepProductSelectCallback(value) {
      //   mRequest('deepApi/deepProductInfo', {id: value}, (res) => {
      //     const deepProductInfo = this.R.path(['data', 'deepProductInfo'], res)
      //
      //     this.dataForm['deepTypeList'] = deepProductInfo['deepTypeList']
      //     this.dataForm['colorNo'] = deepProductInfo['colorNo']
      //
      //   })
      // },
      // addNewDeepProduct() {
      //   const cb = (newValue) => {
      //     this.initDeepProductInfoList()
      //     this.dataForm.deepProductId = newValue.id
      //     this.deepProductSelectCallback(this.dataForm.deepProductId)
      //   }
      //   this.$parent.openDeepProductInfoDialog(cb)
      // },
      addNewDeepType(){
        const cb = (newValue) => {
          this.initDeepCategoryList('deepCategoryList')
          this.dataForm.deepCategoryList = newValue.id
        }
        this.$parent.openDeepCategoryInfoDialog(cb)
      },
      addNewClientInfo() {
        const cb = (newValue) => {
          this.initClientInfoList()
          this.dataForm.clientId = newValue.id
        }
        this.$parent.openClientInfoDialog(cb)
      },
      contractOrderSelectCallback(value) {
          mRequest('contractApi/contractOrderInfoInfo', {id: value}, (res) => {
            const contractOrderInfo = this.R.path(['data', 'contractOrderInfo'], res)

            this.dataForm['clientId'] = contractOrderInfo['clientId']

          })
      }
    }
  }
</script>
